package com.icss.ah.shopVipSet.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.icss.ah.base.action.BaseAction;
import com.icss.ah.base.bean.EasyuiDataGridJson;
import com.icss.ah.base.bean.Json;
import com.icss.ah.login.bean.UserInfoBean;

@Controller
@Scope("prototype")
public class ShopVipInfoAction  extends BaseAction{

	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	
	// json串
	private Json jsonText;
	/**
	 * 进入店铺会员信息展示页面
	 * @return
	 */
	public String toShopVipInfo(){
		try {
			request = this.getRequest();
			String userCode=getUserCodeFromSession(); //从ssession中获取用户编码
			UserInfoBean userInfo=getUserInfo(userCode);
			String shopId=userInfo.getShopId();   //获取店铺id 
			String corpId=userInfo.getCorpId();   //公众号id 
			HashMap map = new HashMap();
			map.put("corpId", corpId);
			map.put("shopId", shopId);
			List<HashMap> theVipCodeList = shopVipInfoService.queryVipCode(map); //查询会员编码
			request.setAttribute("theVipCodeList", theVipCodeList);
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("ShopVipInfo|异常：",e);
		}
		return "toShopVipInfo";
	}
	
	/**
	 * 查询vip信息列表
	 */
	public void queryVipInfoList(){
		request = this.getRequest();
		String result = "";
		try {
			String userCode=getUserCodeFromSession();
			UserInfoBean userInfo=getUserInfo(userCode);
			String shopId=userInfo.getShopId();   //获取店铺id 
			String corpId=userInfo.getCorpId();   //公众号id 
			
			dataGridJson = new EasyuiDataGridJson();
			HashMap map = new HashMap();
			map.put("corpId",corpId);      //公众号id
			map.put("shopId",shopId);
			map.put("userCode",userCode);
			map.put("startNo",Integer.valueOf(getStartIndexMysql()));
			map.put("pageRows",Integer.valueOf(getEndIndexMysql()));
			List<Map> vipList = new ArrayList();
			vipList = shopVipInfoService.queryVipInfoList(map);	
			long vipCount = shopVipInfoService.getVipInfoCount(map);//查询总记录数
			dataGridJson.setRows(vipList);
			dataGridJson.setTotal(vipCount);
			result = JSONObject.fromObject(dataGridJson).toString();
			infolog.info("ShopVipInfo|查询会员信息成功");
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("ShopVipInfo|查询会员信息失败：",e);
		} finally {
			str2Resp(result);
		}
	}
	
	
	
	
	
	

	public Json getJsonText() {
		return jsonText;
	}

	public void setJsonText(Json jsonText) {
		this.jsonText = jsonText;
	}
	
	
	
}
